package com.zmn.oms.services.impl.work;

import com.zmn.oms.common.dio.normal.work.OrderWorkRelationDIO;
import com.zmn.oms.model.entity.work.OrderWorkRelation;
import com.zmn.oms.persistence.interfaces.work.OrderWorkRelationDao;
import com.zmn.oms.services.interfaces.work.OrderWorkRelationService;
import io.shardingsphere.api.HintManager;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author fubiao
 * @since2022年03月22日 11:20
 */
@Service
public class OrderWorkRelationServiceImpl implements OrderWorkRelationService {

    @Resource
    private OrderWorkRelationDao workRelationDao;

    @Override
    public OrderWorkRelation findOrderWorkRelationByOrderIdAndWorkIdSrcMaster(Long orderId, Long workId, Integer type) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();
            return workRelationDao.findOrderWorkRelationByOrderIdAndWorkId(orderId, workId, type);
        }
    }

    @Override
    public OrderWorkRelation findOrderWorkRelationByOrderIdAndWorkId(Long orderId, Long workId, Integer type) {
        return workRelationDao.findOrderWorkRelationByOrderIdAndWorkId(orderId, workId, type);
    }

    @Override
    public Integer insertOrderWorkRelation(OrderWorkRelation workRelation) {
        return workRelationDao.insertOrderWorkRelation(workRelation);
    }

    @Override
    public Integer deleteOrderWorkRelationByWorkIdAndType(Long orderId, Long workId, Integer type) {
        return workRelationDao.deleteOrderWorkRelationByWorkIdAndType(orderId, workId, type);
    }
}
